﻿


//加载品牌
function Getmarker(url) {
    $("#selMarker>option").remove();
    $("#selMarker").append("<option value=\"选品牌\">选品牌</option>");
    $.ajax({
        type: "GET",
        url: url+"ashx/maker.ashx",
        data: "rad=" + Math.random(),
        success: function(res) {

            if (res != "" && res != "[]") {
                var comments = $.parseJSON(res);
                $.each(comments, function(i, n) {
                    $("#selMarker").append("<option value=\"" + n.ID + "\">" + n.CPY + "-" + n.CNAME + "</option>");
                });
            }
        }
    });
}


//加载车系
function GetSerial(url) {

    var maker = jQuery("#selMarker").val();
    jQuery("#selSerial>option").remove();
    jQuery("#selSerial").append("<option value='选车系'>选车系</option>"); 
    if (maker != "选品牌") {
        jQuery.ajax({
        url: url+"ashx/serial.ashx",
            data: "mid=" + maker,
            type: "GET",

            success: function(res) {
           
               if (res != "" && res != "[]") {
                var comments = jQuery.parseJSON(res);
                jQuery.each(comments, function(i, n) {
                   jQuery("#selSerial").append("<option value=\"" + n.ID +"\">" + n.CNAME +"</option>");

                });
               }
      
            }
        })
    } 
}
 
 

//加载车型
function GetModel(url) {
    var maker = $("#selSerial").val();
    $("#selModel>option").remove();
    $("#selModel").append("<option value='选车型'>选车型</option>");
    if (maker != "选车型") {
        $.ajax({
            url: url+"ashx/model.ashx",
            data: "sid=" + maker,
            type: "GET",
            success: function(res) {
                if (res != "" && res != "[]") {
                    var comments = $.parseJSON(res);
                    $.each(comments, function(i, n) {
                        $("#selModel").append("<option value=\"" + n.ID + "\">" + n.CNAME + "</option>");
                    });
                }
            }
        })
    }
}

//检查电话
function checkphone(val) {
    var c = false
    var reg = new RegExp("^1[3,4,5,8]{1}[0-9]{1}[0-9]{8}$");
    if (reg.test(val)) {
        $("#utelphonecheck").text("*");
 
        c = true;
    } else {

              alert("请输入电话号码");
        c = false;
    }
    return c;
}


// 提交团购
function TgClick1(url) {
//    var umessages = $("#umessage").val();
      var umessages = "";
   // var  areatype=  $("#rdodq").val();
     var areatype="潮州"; 
   // var    buytype = $("input[name='rdogc']:checked").val();
      var    buytype ="";
    var uname = $("#username").val();
    var utelphone = $("#usertelphone").val();
    var carmodel = $("#selModel").find("option:selected").text();
    var carserial = $("#selSerial").find("option:selected").text();
    var carmarker = $("#selMarker").find("option:selected").text();
//    if (umessages == "" || umessages == " ") {
//        umessages = "暂无备注";
//    }

    if (carmodel== "请选择") {
    alert("请选择车型");

        return;
    } 
 
    if (uname == "" || uname == " ") {
      
      alert("请输入姓名");
        return;
    } else {
   
       $("#namecheck").text("*");
    }
    if (checkphone(utelphone) == false) {
        return;
    }

    $.ajax({
        url:url+ "ashx/tg.ashx",
        data: "str=" + escape(carmarker) + "|" + escape(carserial) + "|" + escape(carmodel) + "|" + escape(utelphone) + "|" + escape(uname) + "|" + escape(areatype) + "|" + escape(buytype) + "|" + escape(umessages),
        type: "GET",
        success: function(res) {
            if ((res == "true")) {
            $("#username").val("");
             $("#usertelphone").val("");
                alert("报名成功，请等待通知");
            }
            else {
                alert("报名失败,请检查！");
            } 
        }
    })
}


//自定义提交团购
function TgAuto(carmarker, carserial, carmodel, uname, utelphone) {
   
    var umessages = "";
    var areatype = "潮州";
   
    var buytype = "";


    if (carmodel == "") {
        alert("请选择车型");

        return;
    }

    if ($("#"+uname).val() == "" || $("#"+uname).val() == " ") {

        alert("请输入姓名");
        return;
    }
  

    if (checkphone($("#"+utelphone).val()) == false) {
        return;
    }

    $.ajax({
        url: "/ashx/tg.ashx",
        data: "str=" + escape(carmarker) + "|" + escape(carserial) + "|" + escape(carmodel) + "|" + escape($("#" + utelphone).val()) + "|" + escape($("#" + uname).val()) + "|" + escape(areatype) + "|" + escape(buytype) + "|" + escape(umessages),
        type: "GET",
        success: function (res) {
            if ((res == "true")) {
                $("#"+uname).val("");
                $("#"+utelphone).val("");
                alert("报名成功，请等待通知");
            }
            else {
                alert("报名失败,请检查！");
            }
        }
    })
}